﻿using HelloWPF.DataBinding.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HelloWPF.DataBinding.DBAccess
{
    public class LocalDBService
    {
        private List<Teacher> Teachers = new List<Teacher>();

        public LocalDBService()
        {
            Init();
        }

        private void Init()
        {
            for (int i = 0; i < 30; i++)
            {
                Teachers.Add(new Teacher()
                {
                    Teacher_Id = $"Id{i}",
                    Teacher_Name=$"Name{i}"
                });
            }
        }

        /// <summary>
        /// 得到老师
        /// </summary>
        /// <returns></returns>
        public List<Teacher> GetTeachers()
        {
            return Teachers;
        }

        /// <summary>
        /// 添加老师
        /// </summary>
        /// <returns></returns>
        public void AddTeacher(Teacher teacher)
        {
            Teachers.Add(teacher);
        }



        /// <summary>
        /// 删除老师
        /// </summary>
        /// <returns></returns>
        public List<Teacher> DeleteTeacher(string teacher_Id)
        {
            Teacher currentTeacher = Teachers.FirstOrDefault(t => t.Teacher_Id == teacher_Id);
            if (currentTeacher != null)
            {
                Teachers.Remove(currentTeacher);
            }
            return Teachers;
        }

        /// <summary>
        /// 通过名称查找老师
        /// </summary>
        /// <returns></returns>
        public List<Teacher> GetTeacherByName(string teacher_name)
        {
            List<Teacher> teachers  = Teachers.Where(t => t.Teacher_Name.Contains(teacher_name)).ToList();
           
            return teachers;
        }


        /// <summary>
        /// 通过Id查找老师
        /// </summary>
        /// <returns></returns>
        public Teacher GetTeacherById(string teacher_Id)
        {
            Teacher teacher = Teachers.FirstOrDefault(t => t.Teacher_Id == teacher_Id);
            
            return teacher;
        }
    }
}
